$(function() {
	var date = new Date();
	var year = date.getFullYear();
	var beginOfYear = year + "-01-01";
	var endOfYear = year + "-12-31";
	vm.q.endDateS = beginOfYear;
	vm.q.endDateE = endOfYear;
	$("#roomNum").keyup(
			function() {
				$.ajax({
					type : "POST",
					url : baseURL + "asset/select?roomNum="
							+ $("#roomNum").val(),
					success : function(r) {
						if (r.code === 0) {
							var str = "";
							$.each(r.menuList, function(i, n) {
								str += "<div class='div_item' data-id='"
										+ n.assetId + "' data-name='"
										+ n.roomNum + "'>" + n.roomNum
										+ "</div>"
							});
							$("#div_items1").html(str);
							$("#div_items1").show();

							$(".div_item").unbind("click").bind(
									"click",
									function() {
										$("#roomNum").val(
												$(this).attr("data-name"));
										$("#roomNumQuery").val(
												$(this).attr("data-id"));
										vm.q.roomNum = $(this).attr("data-id");
										$("#div_items1").hide();
									});

						} else {
							alert(r.msg);
						}
					}
				});
			});
	$("#roomNum2")
			.keyup(
					function() {
						$
								.ajax({
									type : "POST",
									url : baseURL + "asset/select?roomNum="
											+ $("#roomNum2").val(),
									success : function(r) {
										if (r.code === 0) {
											var str = "";
											$
													.each(
															r.menuList,
															function(i, n) {
																str += "<div class='div_item' data-id='"
																		+ n.assetId
																		+ "' data-name='"
																		+ n.roomNum
																		+ "'>"
																		+ n.roomNum
																		+ "</div>"
															});
											$("#div_items").html(str);
											$("#div_items").show();

											$(".div_item")
													.unbind("click")
													.bind(
															"click",
															function() {
																$exist = $(
																		"#roomNumList")
																		.find(
																				"span[data-id='"
																						+ $(
																								this)
																								.attr(
																										"data-id")
																						+ "']");
																if ($exist.length > 0) {
																	alert("该房号已选择");
																	return;
																}
																var str = "<span class='room' data-id='"
																		+ $(
																				this)
																				.attr(
																						"data-id")
																		+ "'>"
																		+ $(
																				this)
																				.attr(
																						"data-name")
																		+ "<i class='close'>×</i></span>";
																$(
																		"#roomNumList")
																		.append(
																				str);
																$("#roomNums")
																		.val(
																				$(
																						"#roomNums")
																						.val()
																						+ $(
																								this)
																								.attr(
																										"data-id")
																						+ ";");
																$("#div_items")
																		.hide();
																$("#roomNum2")
																		.val("");

																$(".close")
																		.unbind(
																				"click")
																		.bind(
																				"click",
																				function() {
																					$(
																							this)
																							.closest(
																									"span")
																							.remove();
																					var room = "";
																					$
																							.each(
																									$(".room"),
																									function(
																											i,
																											n) {
																										room += $(
																												n)
																												.attr(
																														"data-id")
																												+ ";";
																									});
																					$(
																							"#roomNums")
																							.val(
																									room);
																				});
															});

										} else {
											alert(r.msg);
										}
									}
								});
					});
	$("#roomNum2,#roomNum").unbind('keydown').bind('keydown', function(e) {
		var keyCode = e.keyCode;
		if (keyCode == 9) {
			$("#div_items,#div_items1").hide();
		}
	});
	$(document).unbind('mouseup.parentCls').bind(
			'mouseup.parentCls',
			function(e) {
				var $target = $(e.target);
				if ($target.is('[disabled]') || $target.is('[disabled="true"]')
						|| $target.is('[readonly]')
						|| $target.is('[readonly="readonly"]')) {
					return true;
				}
				if ($(e.target).closest('.parentCls').length == 0) {
					$("#div_items,#div_items1").hide();
				}
			});
	$("#roomNum2").focus(function() {
		if ($("#roomNum2").val()) {
			$("#div_items").show();
		}
	})
	$("#jqGrid").jqGrid(
			{
				url : baseURL + 'comcontract/list',
				datatype : "json",
				postData : {
					'roomNum' : vm.q.roomNum,
					"contractNo" : vm.q.contractNo,
					"rentUser" : vm.q.rentUser,
					"endDateS" : vm.q.endDateS,
					"endDateE" : vm.q.endDateE,
					"salesMan" : vm.q.salesMan
				},
				colModel : [ {
					label : '合同Id',
					name : 'contractId',
					index : 'contract_id',
					width : 60,
					key : true,
					sortable : false,
					hidden : true
				}, {
					label : '合同号',
					name : 'contractNo',
					index : 'contract_no',
					width : 150,
					sortable : false
				}, {
					label : '房号',
					name : 'roomNum',
					width : 150,
					sortable : false
				}, {
					label : '租赁人',
					name : 'rentUser',
					width : 80,
					sortable : false
				}, {
					label : '合同开始日期',
					name : 'startDate',
					index : 'start_date',
					width : 120,
					sortable : false
				}, {
					label : '合同截止日期',
					name : 'endDate',
					index : 'end_date',
					width : 120,
					sortable : false
				}, {
					label : '签订人',
					name : 'salesMan',
					width : 80,
					sortable : false
				}, {
					label : '签订日期',
					name : 'salesDate',
					width : 100,
					sortable : false
				}, {
					label : '租期（月）',
					name : 'dateLong',
					index : 'date_long',
					width : 80,
					sortable : false
				}, {
					label : '面积(㎡)',
					name : 'totalSquare',
					width : 80,
					sortable : false
				}, {
					label : '租金',
					name : 'unitPrice',
					index : 'unit_price',
					width : 80,
					sortable : false
				}, {
					label : '管理费',
					name : 'unitManage',
					index : 'unit_manage',
					width : 80,
					sortable : false
				}, {
					label : '物业费',
					name : 'unitProperty',
					index : 'unit_property',
					width : 80,
					sortable : false
				}, {
					label : '公共能耗费',
					name : 'unitEnergy',
					index : 'unit_energy',
					width : 100,
					sortable : false
				}, {
					label : '保证金',
					name : 'unitBond',
					index : 'unit_bond',
					width : 100,
					sortable : false
				}, {
					label : '居间服务费',
					name : 'unitInter',
					index : 'unit_nter',
					width : 100,
					sortable : false
				}, {
					label : '停车费',
					name : 'unitStop',
					index : 'unit_stop',
					width : 80,
					sortable : false
				}, {
					label : '租场费',
					name : 'unitOther1',
					index : 'unit_other1',
					width : 80,
					sortable : false
				}, {
					label : '其他',
					name : 'unitOther',
					index : 'unit_other',
					width : 80,
					sortable : false
				}, {
					label : '租金',
					name : 'totalPrice',
					index : 'total_price',
					width : 80,
					sortable : false
				}, {
					label : '管理费',
					name : 'totalManage',
					index : 'total_manage',
					width : 80,
					sortable : false
				}, {
					label : '物业费',
					name : 'totalProperty',
					index : 'total_property',
					width : 80,
					sortable : false
				}, {
					label : '公共能耗费',
					name : 'totalEnergy',
					index : 'total_energy',
					width : 100,
					sortable : false
				}, {
					label : '保证金',
					name : 'totalBond',
					index : 'total_bond',
					width : 100,
					sortable : false
				}, {
					label : '居间服务费',
					name : 'totalInter',
					index : 'total_nter',
					width : 100,
					sortable : false
				}, {
					label : '停车费',
					name : 'totalStop',
					index : 'total_stop',
					width : 80,
					sortable : false
				}, {
					label : '租场费',
					name : 'totalOther1',
					index : 'total_other1',
					width : 80,
					sortable : false
				}, {
					label : '其他',
					name : 'totalOther',
					index : 'total_other',
					width : 80,
					sortable : false
				}, {
					label : '总计',
					name : 'totalMoney',
					width : 80,
					sortable : false
				}, {
					label : '单价租金',
					name : 'unitLprice',
					width : 80
				}, {
					label : '总租金',
					name : 'totalLprice',
					width : 80
				}, {
					label : '返租合同号',
					name : 'leasebackContract',
					width : 150
				}, {
					label : '租金',
					name : 'supplePrice',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '管理费',
					name : 'suppleManage',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '物业费',
					name : 'suppleProperty',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '公共能耗费',
					name : 'suppleEnergy',
					index : '',
					width : 100,
					sortable : false
				}, {
					label : '保证金',
					name : 'suppleBond',
					index : '',
					width : 100,
					sortable : false
				}, {
					label : '居间服务费',
					name : 'suppleInter',
					index : 'supple_nter',
					width : 100,
					sortable : false
				}, {
					label : '停车费',
					name : 'suppleStop',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '租场费',
					name : 'suppleOther1',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '其他',
					name : 'suppleOther',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '租金',
					name : 'stotalPrice',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '管理费',
					name : 'stotalManage',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '物业费',
					name : 'stotalProperty',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '公共能耗费',
					name : 'stotalEnergy',
					index : '',
					width : 100,
					sortable : false
				}, {
					label : '保证金',
					name : 'stotalBond',
					index : '',
					width : 100,
					sortable : false
				}, {
					label : '居间服务费',
					name : 'stotalInter',
					index : '',
					width : 100,
					sortable : false
				}, {
					label : '停车费',
					name : 'stotalStop',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '租场费',
					name : 'stotalOther1',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '其他',
					name : 'stotalOther',
					index : '',
					width : 80,
					sortable : false
				}, {
					label : '总计',
					name : 'suppleTotal',
					width : 80,
					sortable : false
				}, {
					label : '生效日期',
					name : 'effectDate',
					index : '',
					width : 120,
					sortable : false
				} ],
				viewrecords : true,
				height : 385,
				rowNum : 10,
				shrinkToFit : false,
				rowList : [ 10, 30, 50 ],
				rownumbers : true,
				rownumWidth : 25,
				autowidth : true,
				multiselect : true,
				footerrow : true,
				gridComplete : function() {
					$(".supple").click(function() {
						alert($(e.target).attr("contract"))
					});
					$(".end").click(function() {
						alert($(this).attr("contract"))
					});
				},
				pager : "#jqGridPager",
				jsonReader : {
					root : "page.list",
					page : "page.currPage",
					total : "page.totalPage",
					records : "page.totalCount"
				},
				prmNames : {
					page : "page",
					rows : "limit",
					order : "order"
				},
				gridComplete : function() {
					// jqGrid底部合计
					var rowNum = parseInt($(this).getGridParam("records"), 10);
					if (rowNum > 0) {
						$(".ui-jqgrid-sdiv").show();
						$(this).footerData(
								"set",
								{
									"contractNo" : "合计",
									"dateLong" : $(this).getCol("dateLong",
											false, "sum"),
									"totalSquare" : $(this).getCol(
											"totalSquare", false, "sum")
											.toFixed(2),
									"unitPrice" : $(this).getCol("unitPrice",
											false, "sum").toFixed(2),
									"unitManage" : $(this).getCol("unitManage",
											false, "sum").toFixed(2),
									"unitProperty" : $(this).getCol(
											"unitProperty", false, "sum")
											.toFixed(2),
									"unitEnergy" : $(this).getCol("unitEnergy",
											false, "sum").toFixed(2),
									"unitBond" : $(this).getCol("unitBond",
											false, "sum").toFixed(2),
									"unitInter" : $(this).getCol("unitInter",
											false, "sum").toFixed(2),
									"unitStop" : $(this).getCol("unitStop",
											false, "sum").toFixed(2),
									"unitOther1" : $(this).getCol("unitOther1",
											false, "sum").toFixed(2),
									"unitOther" : $(this).getCol("unitOther",
											false, "sum").toFixed(2),
									"totalPrice" : $(this).getCol("totalPrice",
											false, "sum").toFixed(2),
									"totalManage" : $(this).getCol(
											"totalManage", false, "sum")
											.toFixed(2),
									"totalProperty" : $(this).getCol(
											"totalProperty", false, "sum")
											.toFixed(2),
									"totalEnergy" : $(this).getCol(
											"totalEnergy", false, "sum")
											.toFixed(2),
									"totalBond" : $(this).getCol("totalBond",
											false, "sum").toFixed(2),
									"totalInter" : $(this).getCol("totalInter",
											false, "sum").toFixed(2),
									"totalStop" : $(this).getCol("totalStop",
											false, "sum").toFixed(2),
									"totalOther1" : $(this).getCol(
											"totalOther1", false, "sum")
											.toFixed(2),
									"totalOther" : $(this).getCol("totalOther",
											false, "sum").toFixed(2),
									"totalMoney" : $(this).getCol("totalMoney",
											false, "sum").toFixed(2),
									"unitLprice" : $(this).getCol("unitLprice",
											false, "sum").toFixed(2),
									"totalLprice" : $(this).getCol(
											"totalLprice", false, "sum")
											.toFixed(2),
									"supplePrice" : $(this).getCol(
											"supplePrice", false, "sum")
											.toFixed(2),
									"suppleManage" : $(this).getCol(
											"suppleManage", false, "sum")
											.toFixed(2),
									"suppleProperty" : $(this).getCol(
											"suppleProperty", false, "sum")
											.toFixed(2),
									"suppleEnergy" : $(this).getCol(
											"suppleEnergy", false, "sum")
											.toFixed(2),
									"suppleBond" : $(this).getCol("suppleBond",
											false, "sum").toFixed(2),
									"suppleInter" : $(this).getCol(
											"suppleInter", false, "sum")
											.toFixed(2),
									"suppleStop" : $(this).getCol("suppleStop",
											false, "sum").toFixed(2),
									"suppleOther1" : $(this).getCol(
											"suppleOther1", false, "sum")
											.toFixed(2),
									"suppleOther" : $(this).getCol(
											"suppleOther", false, "sum")
											.toFixed(2),
									"stotalPrice" : $(this).getCol(
											"stotalPrice", false, "sum")
											.toFixed(2),
									"stotalManage" : $(this).getCol(
											"stotalManage", false, "sum")
											.toFixed(2),
									"stotalProperty" : $(this).getCol(
											"stotalProperty", false, "sum")
											.toFixed(2),
									"stotalEnergy" : $(this).getCol(
											"stotalEnergy", false, "sum")
											.toFixed(2),
									"stotalBond" : $(this).getCol("stotalBond",
											false, "sum").toFixed(2),
									"stotalInter" : $(this).getCol(
											"stotalInter", false, "sum")
											.toFixed(2),
									"stotalStop" : $(this).getCol("stotalStop",
											false, "sum").toFixed(2),
									"stotalOther1" : $(this).getCol(
											"stotalOther1", false, "sum")
											.toFixed(2),
									"stotalOther" : $(this).getCol(
											"stotalOther", false, "sum")
											.toFixed(2),
									"suppleTotal" : $(this).getCol(
											"suppleTotal", false, "sum")
											.toFixed(2)
								}); // 将合计值显示出来
					} else {
						$(".ui-jqgrid-sdiv").hide();
					}
				}
			});
	$("#jqGrid").jqGrid("setGroupHeaders", {
		useColSpanStyle : true,// 没有表头的列是否与表头所在行的空单元格合并
		groupHeaders : [ {
			startColumnName : "unitPrice",// 合并列的起始位置 colModel中的name
			numberOfColumns : 9, // 合并列数 包含起始列
			titleText : "单价"// 表头
		}, {
			startColumnName : "totalPrice",
			numberOfColumns : 9,
			titleText : "含税总金额"
		}, {
			startColumnName : "unitLprice",
			numberOfColumns : 2,
			titleText : "返租金额"
		}, {
			startColumnName : "supplePrice",
			numberOfColumns : 9,
			titleText : "变更单价"
		}, {
			startColumnName : "stotalPrice",
			numberOfColumns : 9,
			titleText : "变更后价格"
		} ]
	});
	new AjaxUpload('#upload', {
		action : baseURL + 'comimage/upload?token=' + token,
		name : 'file',
		autoSubmit : true,
		responseType : "json",
		onSubmit : function(file, extension) {

			if (!(extension && /^(jpg|jpeg|png|gif)$/.test(extension
					.toLowerCase()))) {
				alert('只支持jpg、png、gif格式的图片！');
				return false;
			}
		},
		onComplete : function(file, r) {
			if (r.code == 0) {
				var imageIds = $("#imageIds").val();
				$.get(baseURL + "comimage/getPhoto?imageId=" + r.imageId,
						function(v) {
							imageIds += r.imageId + ";";
							$("#imageIds").val(imageIds);
							vm.comContract.imageIds = imageIds;
							$("#imageList").append(
									'<img width="100" height="150" src="data:image/png;base64,'
											+ v.imageStr
											+ '" data-action="zoom"/>');
						});
			} else {
				alert(v.msg);
			}
		}
	});
	new AjaxUpload('#upload1', {
		action : baseURL + 'comimage/upload?token=' + token,
		name : 'file',
		autoSubmit : true,
		responseType : "json",
		onSubmit : function(file, extension) {

			if (!(extension && /^(jpg|jpeg|png|gif)$/.test(extension
					.toLowerCase()))) {
				alert('只支持jpg、png、gif格式的图片！');
				return false;
			}
		},
		onComplete : function(file, r) {
			if (r.code == 0) {
				var imageIds = $("#imageIds1").val();
				$.get(baseURL + "comimage/getPhoto?imageId=" + r.imageId,
						function(v) {
							imageIds += r.imageId + ";";
							$("#imageIds1").val(imageIds);
							vm.comContract.imageIds1 = imageIds;
							$("#imageList1").append(
									'<img width="100" height="150" src="data:image/png;base64,'
											+ v.imageStr
											+ '" data-action="zoom"/>');
						});
			} else {
				alert(v.msg);
			}
		}
	});

});
var setting = {
	check : {
		enable : true,
		chkStyle : "checkbox",
		chkboxType : {
			"Y" : "s",
			"N" : "ps"
		}
	},

	data : {
		simpleData : {
			enable : true,
			idKey : "menuId",
			pIdKey : "parentId",
			rootPId : -1
		},
		key : {
			url : "nourl"
		}
	}
};
var ztree;
var str = ""; // 这是一字符串
var vm = new Vue(
		{
			el : '#rrapp',
			data : {
				q : {
					contractNo : "",
					roomNum : "",
					rentUser : "",
					endDateS : "",
					endDateE : "",
					salesMan : ""
				},
				showList : true,
				title : null,
				comContract : {
					leasebackFlag : 1,
					suppleFlag : 1,
					imageIds : "",
					imageIds1 : "",
					startDate : "",
					effectDate : "",
					endDate : "",
					salesDate : ""
				},
				menu : {}
			},
			methods : {
				exportExcel : function() {

					location.href = baseURL
							+ "comcontract/contractExport?endDateS="
							+ vm.q.endDateS + "&endDateE=" + vm.q.endDateE
							+ "&salesMan=" + vm.q.salesMan + "&rentUser="
							+ vm.q.rentUser + "&roomNum=" + vm.q.roomNum
							+ "&contractNo=" + vm.q.contractNo + "&token="
							+ token;
				},
				supple : function(e) {
					var contractId = getSelectedRow();
					if (contractId == null) {
						return;
					}
					$.get(baseURL + "comcontract/info/" + contractId, function(
							r) {
						vm.comContract = r.comContract;
						layer.open({
							type : 1,
							skin : 'layui-layer-molv',
							title : "变更",
							area : [ '600px', '650px' ],
							shadeClose : false,
							content : jQuery("#suppleLayer"),
							btn : [ '修改', '取消' ],
							btn1 : function(index) {
								var data = "contractId=" + contractId;
								$.ajax({
									type : "POST",
									url : baseURL + "comcontract/updateSupple",
									data : JSON.stringify(vm.comContract),
									success : function(r) {
										if (r.code == 0) {
											layer.close(index);
											layer.alert('修改成功', function() {
												location.reload();
											});
										} else {
											layer.alert(r.msg);
										}
									}
								});
							}
						});
					});
				},
				end : function(e) {
					var contractId = getSelectedRow();
					if (contractId == null) {
						return;
					}
					vm.comContract.contractId = contractId;
					layer.open({
						type : 1,
						skin : 'layui-layer-molv',
						title : "终止合同",
						area : [ '600px', '350px' ],
						shadeClose : false,
						content : jQuery("#endLayer"),
						btn : [ '修改', '取消' ],
						btn1 : function(index) {
							$.ajax({
								type : "POST",
								url : baseURL + "comcontract/endContract",
								data : JSON.stringify(vm.comContract),
								success : function(r) {
									if (r.code == 0) {
										layer.close(index);
										layer.alert('修改成功', function() {
											location.reload();
										});
									} else {
										layer.alert(r.msg);
									}
								}
							});
						}
					});
				},
				query : function() {
					vm.reload();
				},
				getMenu : function() {
					// 加载菜单树
					$.get(baseURL + "asset/select", function(r) {
						ztree = $.fn.zTree.init($("#menuTree"), setting,
								r.menuList);
						var node = ztree.getNodeByParam("menuId",
								vm.menu.parentId);
						ztree.selectNode(node);

						vm.menu.parentName = node.name;
					})
				},
				add : function() {
					vm.showList = false;
					vm.title = "新增";
					vm.comContract = {
						leasebackFlag : 1,
						suppleFlag : 1,
						imageIds : "",
						startDate : "",
						endDate : "",
						effectDate : "",
						salesDate : ""
					};
					vm.getMenu();
					$("#imageList").html("");
					$('#startDate').val("");
					$('#endDate').val("");
					$('#effectDate').val("");
					$('#salesDate').val("");
					$('#roomNums').val("");
					$('#roomNumList').empty();

				},
				update : function(event) {
					var contractId = getSelectedRow();
					if (contractId == null) {
						return;
					}
					vm.showList = false;
					vm.title = "修改";
					$("#imageList").html("");
					vm.getInfo(contractId);
					vm.comContract = {
						leasebackFlag : 1,
						imageIds : "",
						startDate : vm.comContract.startDate,
						endDate : vm.comContract.endDate,
						effectDate : vm.comContract.effectDate,
						salesDate : vm.comContract.salesDate
					};
				},
				saveOrUpdate : function(event) {
					var url = vm.comContract.contractId == null ? "comcontract/save"
							: "comcontract/update";
					vm.comContract.assetIds = $("#roomNums").val();
					$.ajax({
						type : "POST",
						url : baseURL + url,
						data : JSON.stringify(vm.comContract),
						success : function(r) {
							if (r.code === 0) {
								alert('操作成功', function(index) {
									vm.reload();
								});
							} else {
								alert(r.msg);
							}
						}
					});
				},
				del : function(event) {
					var contractIds = getSelectedRows();
					if (contractIds == null) {
						return;
					}

					confirm('确定要删除选中的记录？', function() {
						$.ajax({
							type : "POST",
							url : baseURL + "comcontract/delete",
							data : JSON.stringify(contractIds),
							success : function(r) {
								if (r.code == 0) {
									alert('操作成功', function(index) {
										$("#jqGrid").trigger("reloadGrid");
									});
								} else {
									alert(r.msg);
								}
							}
						});
					});
				},

				buildTree : function() {
					layer.open({
						type : 1,
						offset : '50px',
						skin : 'layui-layer-molv',
						title : "选择菜单",
						area : [ '300px', '450px' ],
						shade : 0,
						shadeClose : false,
						content : jQuery("#menuLayer"),
						btn : [ '确定', '取消' ],
						btn1 : function(index) {
							var node = ztree.getSelectedNodes();
							// 选择上级菜单
							vm.menu.parentId = node[0].menuId;
							vm.menu.parentName = node[0].name;
							layer.close(index);
						}
					});
				},

				getInfo : function(contractId) {
					$
							.get(
									baseURL + "comcontract/info/" + contractId,
									function(r) {
										vm.comContract = r.comContract;
										str = r.comContract.imageIds;
										asset = r.comContract.assetIds;
										$("#roomNums").val(asset);
										$('#roomNumList').empty();
										if (str) {

											var strs = str.split(";"); // 字符分割
											for (i = 0; i < strs.length; i++) {
												if (strs[i]) {
													$
															.get(
																	baseURL
																			+ "comimage/getPhoto?imageId="
																			+ strs[i],
																	function(v) {
																		$(
																				"#imageList")
																				.append(
																						'<img width="100" height="150" src="data:image/png;base64,'
																								+ v.imageStr
																								+ '" data-action="zoom"/>');
																	});
												}
											}
										}
										if (asset) {

											var strs = asset.split(";"); // 字符分割

											for (i = 0; i < strs.length; i++) {
												if (strs[i]) {
													$
															.get(
																	baseURL
																			+ "asset/info/"
																			+ strs[i],
																	function(v) {
																		var str = "<span class='room' data-id='"
																				+ v.comAsset.assetId
																				+ "'>"
																				+ v.comAsset.roomNum
																				+ "<i class='close'>×</i></span>";
																		$(
																				"#roomNumList")
																				.append(
																						str);
																	});
													$(".close")
															.unbind("click")
															.bind(
																	"click",
																	function() {
																		$(this)
																				.closest(
																						"span")
																				.remove();
																		var room = "";
																		$
																				.each(
																						$(".room"),
																						function(
																								i,
																								n) {
																							room += $(
																									n)
																									.attr(
																											"data-id")
																									+ ";";
																						});
																		$(
																				"#roomNums")
																				.val(
																						room);
																	});
												}
											}
										}
									});

				},
				reload : function(event) {
					vm.showList = true;
					var page = $("#jqGrid").jqGrid('getGridParam', 'page');
					$("#jqGrid").jqGrid('setGridParam', {
						postData : {
							'roomNum' : vm.q.roomNum,
							"contractNo" : vm.q.contractNo,
							"rentUser" : vm.q.rentUser,
							"endDateS" : vm.q.endDateS,
							"endDateE" : vm.q.endDateE,
							"salesMan" : vm.q.salesMan
						},
						page : page
					}).trigger("reloadGrid");
				}
			}
		});

$(function() {
	$('#startDate').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#startDate').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#startDate').val(year + '-' + month + '-' + day);
				vm.comContract.startDate = year + '-' + month + '-' + day;
			});

	$('#endDate').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#endDate').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#endDate').val(year + '-' + month + '-' + day);
				vm.comContract.endDate = year + '-' + month + '-' + day;
			});
	$('#endDate2').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#endDate2').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#endDate2').val(year + '-' + month + '-' + day);
				vm.comContract.endDate = year + '-' + month + '-' + day;
			});
	$('#effectDate').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#effectDate').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#effectDate').val(year + '-' + month + '-' + day);
				vm.comContract.effectDate = year + '-' + month + '-' + day;
			});
	$('#effectDate2').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#effectDate2').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#effectDate2').val(year + '-' + month + '-' + day);
				vm.comContract.effectDate = year + '-' + month + '-' + day;
			});
	$('#endDateS').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#endDateS').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#endDateS').val(year + '-' + month + '-' + day);
				vm.q.endDateS = year + '-' + month + '-' + day;
			});
	$('#endDateE').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#endDateE').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#endDateE').val(year + '-' + month + '-' + day);
				vm.q.endDateE = year + '-' + month + '-' + day;
			});
	$('#salesDate').datepicker().on('changeDate.datepicker.amui',
			function(event) {
				$('#salesDate').text("");
				var date = new Date(event.date);
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10) {
					month = '0' + month;
				}
				var day = date.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				$('#salesDate').val(year + '-' + month + '-' + day);
				vm.comContract.salesDate = year + '-' + month + '-' + day;
			});

	$('#endDateE').keyup(function(e) {
		if (e.keyCode == 8) {
			$('#endDateE').val();
			$('#endDateE').text("");
			vm.q.endDateE = "";
		}
	});
	$('#endDateS').keyup(function(e) {
		if (e.keyCode == 8) {
			$('#endDateS').val();
			$('#endDateS').text("");
			vm.q.endDateS = "";
		}
	});
	$('#roomNum').keyup(function(e) {
		if (e.keyCode == 8) {
			$('#roomNum').val();
			vm.q.roomNum = "";
		}
	});

})